<?php
namespace app\index\controller;
use \think\Controller;
use \think\Request;
use \think\Session;
use \think\Db;

class Login extends Controller
{
    public function index()
    {
        return $this->fetch('index',['title'=>'用户登录 - 蒸汽男孩论坛']);
    }

    public function doLogin(Request $req)
    {
        $phone = isset($_POST['phone'])?trim($_POST['phone']) : null;
    	$pass = isset($_POST['pass'])?trim($_POST['pass']) : null;

    	$data = Db::name('user')->where(['phone'=>$phone,'pass'=>md5($pass)])->find();
        // var_dump($data);
    	if(!empty($data)) {
            // 将匹配到用户信息存入session
            Session::set('person',$data);
    		return 'ok';
    	} else {
    		return 'no';
    	}
    }

    public function outLogin()
    {
        Session::delete('person');
        $this->success('退出成功','index/index/index');
    }
}
